package com.pig4cloud.pig.module.controller.intermediary;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.common.mybatis.page.PageUtils;
import com.pig4cloud.pig.common.mybatis.page.TableDataInfo;
import com.pig4cloud.pig.module.api.entity.intermediary.IntermediaryInfo;
import com.pig4cloud.pig.module.service.intermediary.IIntermediaryInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2022-08-19
 */
@Validated
@Api(value = "【请填写功能名称】控制器", tags = {"【请填写功能名称】管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/info")
public class IntermediaryInfoController {

    private final IIntermediaryInfoService intermediaryInfoService;

    /**
     * 查询【请填写功能名称】列表
     */
    @ApiOperation("查询【请填写功能名称】列表")
    @PreAuthorize("@pms.hasPermission('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo<IntermediaryInfo> list(@Validated IntermediaryInfo intermediaryInfo) {
        QueryWrapper<IntermediaryInfo> qw = new QueryWrapper<>();

        TableDataInfo<IntermediaryInfo> td = PageUtils.buildDataInfo(intermediaryInfoService.page(PageUtils.buildPage(),qw));
        List<IntermediaryInfo> list = td.getData();
        return td;
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @ApiOperation("导出【请填写功能名称】列表")
    @PreAuthorize("@pms.hasPermission('system:info:export')")
    @SysLog("【请填写功能名称】")
    @GetMapping("/export")
    public List export(@Validated IntermediaryInfo intermediaryInfo) {
        List<IntermediaryInfo> list = intermediaryInfoService.list();
        // ExcelUtil<IntermediaryInfo> util = new // ExcelUtil<IntermediaryInfo>(IntermediaryInfo.class);
        return  list;// util.exportExcel(list, "【请填写功能名称】");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @ApiOperation("获取【请填写功能名称】详细信息")
    @PreAuthorize("@pms.hasPermission('system:info:query')")
    @GetMapping("/{id}")
    public R<IntermediaryInfo> getInfo(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) {
        IntermediaryInfo intermediaryInfo = intermediaryInfoService.getById(id);
        return R.ok(intermediaryInfo);
    }

    /**
     * 新增【请填写功能名称】
     */
    @ApiOperation("新增【请填写功能名称】")
    @PreAuthorize("@pms.hasPermission('system:info:add')")
    @SysLog("【请填写功能名称】")

    @PostMapping()
    public R<Void> add(@Valid @RequestBody IntermediaryInfo intermediaryInfo) {
        return R.okByRow(intermediaryInfoService.save(intermediaryInfo) ? 1 : 0);
    }

    /**
     * 修改【请填写功能名称】
     */
    @ApiOperation("修改【请填写功能名称】")
    @PreAuthorize("@pms.hasPermission('system:info:edit')")
    @SysLog("【请填写功能名称】")

    @PutMapping()
    public R<Void> edit(@Valid @RequestBody IntermediaryInfo intermediaryInfo) {
        return R.okByRow(intermediaryInfoService.updateById(intermediaryInfo) ? 1 : 0);
    }

    /**
     * 删除【请填写功能名称】
     */
    @ApiOperation("删除【请填写功能名称】")
    @PreAuthorize("@pms.hasPermission('system:info:remove')")
    @SysLog("【请填写功能名称】")
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")  @PathVariable Long[] ids) {
        return R.okByRow(intermediaryInfoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
